#pragma once

#ifndef __GAME__STATE__MANAGER__INCLUDED_H__
#define __GAME__STATE__MANAGER__INCLUDED_H__

#include "LitPrerequisites.h"
#include "LitGameState.h"
#include "LitGameTask.h"
#include "LitCoreComponent.h"

#include <stack>
#include <vector>

namespace Lit
{
	class LIT_API GameStateManager : public CoreComponent
	{
		typedef std::vector<GameStatePtr>	vec_t;
		typedef std::vector<GameTaskPtr>	task_vec_t;
		typedef std::stack<GameStatePtr>	stack_t;

		typedef vec_t::iterator					iter_t;
		typedef vec_t::const_iterator			const_iter_t;
		typedef task_vec_t::iterator			task_iter_t;
		typedef task_vec_t::const_iterator		task_const_iter_t;
		
		stack_t							mStack;
		vec_t							mStates;
		task_vec_t						mTasks;
		OgreRenderWindowPtr					mWindow;
	public:
		GameStateManager( ) ;
		virtual ~GameStateManager( );
		
		
		void initialise(OgreRenderWindowPtr win, OgreCameraPtr cam, OgreSceneManagerPtr mgr );
		bool renderOneFrame( float dt );
		void shutdown();

		task_iter_t taskBegin();
		task_iter_t taskEnd();
		task_const_iter_t taskBegin() const;
		task_const_iter_t taskEnd() const;
		
		task_iter_t findTask( const String &name );
		task_const_iter_t findTask( const String &name ) const;

		iter_t begin();
		iter_t end();
		const_iter_t begin() const;
		const_iter_t end() const;

		iter_t find( const String &name );
		const_iter_t find( const String &name ) const;
		bool hasState( const String &name ) const;
		void registerState( GameState * state, bool push_on_stack = true );
		void destroyState( const String &name );
		bool hasTask( const String &name ) const;
		void registerTask( GameTask * task );
		void destroyTask( const String &name );
		
		void clearStack( );
		void clearStates( );
		void clearTasks( );

		void clear( );

		void pushState( const String &name );
		void popState( );

		bool updateStates( float dt );

		GameStatePtr currentState() const;
		
	};
	typedef RefPtr<GameStateManager>		GameStateManagerPtr;
};


#endif